package org.springleaf.ui.token;

import java.io.IOException;

import javax.servlet.jsp.JspException;

import org.springleaf.ui.AbstractTag;

/**
 * token生成标签
 * @author leaf
 */
public class TokenTag extends AbstractTag{

	private static final long serialVersionUID = 1L;

	@Override
	public int doEndTag() throws JspException {
		
		TokenHelper helper = new TokenHelper();
		//生成token和tokenName
		String name = helper.createTokenName();
		String token = helper.createToken();
		
		setSessAttr(name, token);
		
		try {
			getOut().write("<input type=\"hidden\" name=\"" + TokenHelper.TOKEN_NAME + "\" value=\"" + name + "\" />");
			getOut().write("<input type=\"hidden\" name=\"" + name + "\" value=\"" + token + "\" />");
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		return super.doEndTag();
	}

}
